<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>系统公告</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
		<!--搜索开始-->
        <fieldset class="layui-elem-field layuimini-search">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="" id="searchFrm">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">学生姓名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="stuName" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">学生班级</label>
                            <div class="layui-input-inline">
                                <select type="text" name="stuClass" lay-filter="stuClass" id="stuClass" autocomplete="off" class="layui-select" lay-search>
									<option value=""></option>
								</select>
                            </div>
                        </div>
					</div>
					<div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">学期</label>
                            <div class="layui-input-inline">
								<select type="text" name="semester" id="semester" autocomplete="off" class="layui-select" lay-search>
									<option value=""></option>
									<option value="第一学期">第一学期</option>
									<option value="第二学期">第二学期</option>
									<option value="第三学期">第三学期</option>
									<option value="第四学期">第四学期</option>
								</select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">收费项</label>
                            <div class="layui-input-inline">
								<select type="text" name="payItem" id="payItem" autocomplete="off" class="layui-select" lay-search>
									<option value=""></option>
									<option value="学费">学费</option>
									<option value="退款">退款</option>
									<option value="其他">其他</option>
								</select>
                            </div>
                        </div>
					</div>
					<div class="layui-form-item">
                        <div class="layui-block" style="text-align: center;">
                            <a class="layui-btn " lay-submit=""  lay-filter="data-search-btn"><label class="layui-icon layui-icon-search"></label>搜索</a>
							<a class="layui-btn layui-btn-warm" onclick="javascript:$('#searchFrm')[0].reset()" lay-filter="data-search-btn"><label class="layui-icon layui-icon-refresh"></label>重置</a>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
		<!--搜索结束-->
		
		<!--表格开始-->
        <table class="layui-hide" id="buspaystuTable" lay-filter="buspaystuTable"></table>
		
		
        <script type="text/html" id="buspaystuToolBar">
            <a class="layui-btn layui-btn-sm" lay-event="add">添加</a>
            <a class="layui-btn layui-btn-sm layui-btn-danger data-count-delete" lay-event="batchdelete">批量删除</a>
        </script>
		<script type="text/html" id="buspaystuTableBar">
			<a class="layui-btn layui-btn-xs layui-btn-warm data-count-delete" lay-event="update">修改</a>
		    <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
			<a class="layui-btn layui-btn-xs layui-btn-warm data-count-delete" lay-event="dis">作废</a>
		</script>
		<!--表格结束-->
		
		<!--添加和修改的弹出层开始-->
		<div id="addOrUpdateDiv" style="display: none;padding: 0.3125rem">
			<form method="post" class="layui-form layui-form-pane" lay-filter="dataFrm" id="dataFrm">
				<div class="layui-form-item">
				    <div class="layui-inline">
				        <label class="layui-form-label">学生姓名</label>
				        <div class="layui-input-inline">
				            <input type="hidden" name="id">
				            <input type="text" name="stuName" autocomplete="off" class="layui-input">
				        </div>
				    </div>
				    <div class="layui-inline">
				        <label class="layui-form-label">学生班级</label>
				        <div class="layui-input-inline">
				            <select type="text" name="stuClass" dislay-filter="stuClass" id="stuClass2" autocomplete="off" class="layui-select" lay-search>
								<option value=""></option>
							</select>
				        </div>
				    </div>
				</div>
				 <div class="layui-form-item">
					<label class="layui-form-label">支付类型</label>
					<div class="layui-input-block">
					  <input type="text" name="payType" lay-verify="required" autocomplete="off" placeholder="支付类型" class="layui-input">
					</div>
				  </div>
				 <div class="layui-form-item">
					<label class="layui-form-label">支付项</label>
					<div class="layui-input-block">
						<select type="text" name="payItem" id="payItem" autocomplete="off" class="layui-select" lay-search>
							<option value=""></option>
							<option value="学费">学费</option>
							<option value="退款">退款</option>
							<option value="其他">其他</option>
						</select>
					</div>
				  </div>
				 <div class="layui-form-item">
					<label class="layui-form-label">学期</label>
					<div class="layui-input-block">
						<select type="text" name="semester" id="semester" autocomplete="off" class="layui-select" lay-search>
							<option value=""></option>
							<option value="第一学期">第一学期</option>
							<option value="第二学期">第二学期</option>
							<option value="第三学期">第三学期</option>
							<option value="第四学期">第四学期</option>
						</select>
					</div>
				  </div>
				  <div class="layui-form-item">
						<label class="layui-form-label">金额</label>
						<div class="layui-input-block">
						  <input type="text" name="money" placeholder="金额" class="layui-input">
						</div>
				   </div>
				  <div class="layui-form-item">
						<label class="layui-form-label">收款人</label>
						<div class="layui-input-block">
							<select type="text" name="payee" id="payee" autocomplete="off" class="layui-select" lay-search>
								<option value=""></option>
								<option value="system">system</option>
								<option value="肖腾">肖腾</option>
							</select>
						</div>
				   </div>
				  <div class="layui-form-item" id="disTop">
						<label class="layui-form-label">备注</label>
						<div class="layui-input-block">
						  <input type="text" name="remark" placeholder="备注" class="layui-input">
						</div>
				   </div>
				  <div class="layui-form-item">
						<div class="layui-input-block" style="text-align: center;">
							<a class="layui-btn " lay-submit=""  lay-filter="doSubmit"><label class="layui-icon layui-icon-release"></label>提交</a>
							<a class="layui-btn layui-btn-warm" onclick="javascript:$('#dataFrm')[0].reset()" lay-filter="data-search-btn"><label class="layui-icon layui-icon-refresh"></label>重置</a>
						</div>
				   </div>
				   
			</form>
		</div>
		<!--添加和修改的弹出层结束-->
    </div>
</div>
<script src="../../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="../../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="../../../lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>
<script src="../../../lib/common/jquery.cookie.min.js" charset="utf-8"></script>
<script src="../../../lib/common/common.js" charset="utf-8"></script>

<script>
    layui.use(['form', 'table','laydate','layer','wangEditor'], function () {
        var form = layui.form;
        var table = layui.table;
		var laydate=layui.laydate;
		var layer=layui.layer;
		var wangEditor = layui.wangEditor;

		$.get(api+'busPayStu/getClassData',function(res){
			// console.log(res)
			var html=document.getElementById("stuClass").innerHTML;
			// console.log(html)
			$.each(res.data,function(i,item){
				html+= '<option value="'+item.classRemark+'">'+item.classRemark+'</option>'
			})
			// console.log(html)
			$('#stuClass').html(html);
			$('#stuClass2').html(html);
			form.render('select');
		})

      var tableIns=table.render({
            elem: '#buspaystuTable',
            url: api+'busPayStu/getData',
			toolbar:"#buspaystuToolBar",
			cellMinWidth: 150 ,//全局定义常规单元格的最小宽度，layui 2.2.1 新增
			height: 'full-100',
            cols: [ [
                {type: "checkbox",  fixed: "left"},
                {field: 'id', title: 'ID', align: "center",width:60 , fixed: "left", unresize: true, sort: true},
                {field: 'stuName',  title: '学生姓名', align: "center",width:100, fixed: "left"}, 
                {field: 'stuClass',  title: '就读班级', align: "center",width:100},
                {field: 'createTime',  title: '缴费时间', align: "center",width:200},
                {field: 'money',  title: '金额', align: "center",width:80},
                {field: 'semester',  title: '学期', align: "center",width:100},
                {field: 'payee',  title: '收款人', align: "center",width:100},
                {field: 'state',  title: '状态', align: "center",width:100},
                {field: 'payType',  title: '支付类型', align: "center",width:100},
                {field: 'payItem',  title: '收费项', align: "center",width:80},
                {field: 'remark',  title: '备注', align: "center"},
                {fixed: 'right',title: '操作', align:'center', templet: '#buspaystuTableBar',width:190}
            ] ],
            page: true
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
			var params= $("#searchFrm").serialize();
            //执行搜索重载
            table.reload('buspaystuTable', {
                page: {
                    curr: 1
                }
                ,url:api+'busPayStu/getData?'+params
            });
			console.log(api+'busPayStu/getData?'+params)
            return false;
        });

		//监听表头的事件
		table.on('toolbar(buspaystuTable)', function(obj){
		  var checkStatus = table.checkStatus(obj.config.id);
		  switch(obj.event){
		    case 'batchdelete':
				batchdelete();
		    break;
			case 'add':
				openAddBusPayStu();
			break;
		  };
		});
		
		//监听行数据的事件
        table.on('tool(buspaystuTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'delete') {
                layer.confirm('真的删除这条数据么', function (index) {
					$.post(api+"busPayStu/removeBusPayStu",{id:data.id},function(res){
						layer.msg(res.msg);
						obj.del();
						layer.close(index);
					})
                });
            }else if(obj.event === 'update'){
				openUpdateBusPayStu(data);
		    }else if(obj.event === 'dis'){
				disabledData(data);
			}
        });
		
		//打开添加公告的弹层
		var mainIndex;
		var url;  //动态的url
		function openAddBusPayStu(){
			mainIndex=layer.open({
				type:1,
				title:'添加公告',
				content:$("#addOrUpdateDiv"),
				area:['800px','600px'],
				success:function(index){
					url=api+"busPayStu/addBusPayStu";
					//重置表单
					$("#dataFrm")[0].reset();
				}
			});	
		}
		//打开修改页面
		function openUpdateBusPayStu(data){
			mainIndex=layer.open({
				type:1,
				title:'修改['+data.title+']公告',
				content:$("#addOrUpdateDiv"),
				area:['800px','600px'],
				success:function(index){
					url=api+"busPayStu/updateBusPayStu";
					//装载数据表格
					form.val("dataFrm",data);
				}
			});	
		}
		//作废缴费
		function disabledData(data){
			$.post(api+"busPayStu/disabledData",{id:data.id,state:'作废'},function(res){
				layer.msg(res.msg);
				tableIns.reload();
			})
		}
		//提交数据
		form.on("submit(doSubmit)",function(data){
			var params= $("#dataFrm").serialize();
			$.post(url,params, function(res){
				layer.msg(res.msg);
				if(res.code==200){
					tableIns.reload();
				}
				layer.close(mainIndex);
			})
			return false;
		})
		
		
		//批量删除
		function batchdelete(){
			var checkStatus = table.checkStatus('buspaystuTable'); //idTest 即为基础参数 id 对应的值
			var data=checkStatus.data;
			var length=checkStatus.data.length;
			// console.log(checkStatus.data) //获取选中行的数据
			// console.log(checkStatus.data.length) //获取选中行数量，可作为是否有选中行的条件
			if(length==0){
				layer.msg("请选中要删除的行数据");
			}else{
				layer.confirm('真的删除选择中这些数据么?', function (index) {
					var params="";
					$.each(data,function(index,item){
						if(index==0){
							params+="id="+item.id;
						}else{
							params+="&id="+item.id;
						}
					});
					$.post(api+"busPayStu/removeBusPayStus",params,function(res){
						layer.msg(res.msg);
						tableIns.reload();
						layer.close(index);
					})
				});
			}
		}

    });
</script>
<script>

</script>

</body>
</html>